package com.group.nepm.publicSuperviseDataManagement.controller;

import com.group.common.utils.MyUtils;
import com.group.nepg.entity.AccurateAqiLevel;
import com.group.nepm.statisticDataManagement.entity.StatisticData;
import com.group.neps.entity.RowAqiData;
import com.group.neps.entity.RowAqiLevel;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Label;

public class GirdOperator_DetailController {

    //设置静态变量以接受数据
    private static StatisticData selectStatisticData;
    private static int Selectid;
    private static String NEPMusername;


    public static void NEPMsetSelectedStatisticData(StatisticData data, int id, String username) {
        selectStatisticData = data;
        Selectid = id;
        NEPMusername = username;
    }

    public static StatisticData NEPMgetSelectedStatisticData() {
        return selectStatisticData;
    }

    @FXML
    private Label AQIId;
    @FXML
    private Label AQILocation;
    @FXML
    private Label AQILevel;
    @FXML
    private Label AQITime;
    @FXML
    private Label NEPGMessage;
    @FXML
    private Label NEPSMessage;
    @FXML
    private Label NEPSDescribe;


    public void initialize() {
        String id = String.format("%d",Selectid);
        String location = selectStatisticData.getRowAqiData().getLocation().getProvince().getName() + " " + selectStatisticData.getRowAqiData().getLocation().getCity().getName() + " " + selectStatisticData.getRowAqiData().getLocation().getAddress();
        AccurateAqiLevel level = selectStatisticData.getAccurateAqiData().getAccurateAqiLevel();

        //通过switch将level转换成AQIlevel
        int key = level.ordinal()+1;
        String AQIlevel = "";
        String describe = "";
        switch (key){
            case 1:{
                AQIlevel = "一级 优";
                describe = "空气质量令人满意，基本无空气污染";
                break;
            }
            case 2:{
                AQIlevel = "二级 良";
                describe = "空气质量可接受，但某些污染物可能对极少数异常敏感人群健康有较弱影响";
                break;
            }
            case 3:{
                AQIlevel = "三级 轻度污染";
                describe = "易感人群症状有轻度加剧，健康人群出现刺激症状";
                break;
            }
            case 4:{
                AQIlevel = "四级 中度污染";
                describe = "进一步加剧易感人群症状，可能对健康人群心脏、呼吸系统有影响";
                break;
            }
            case 5:{
                AQIlevel = "五级 重度污染";
                describe = "心脏病和肺病患者症状显著加剧，运动耐受力降低，健康人群普遍出现症状";
                break;
            }
            case 6:{
                AQIlevel = "六级 严重污染";
                describe = "健康人群运动耐受力降低，有明显强烈症状，提前出现某些疾病";
                break;
            }

        }
        String time = selectStatisticData.getRowAqiData().getTime().toString();
        String nepgMessage = NEPMusername;
        String nepsMessage = selectStatisticData.getRowAqiData().getUser().getUsername() + " " + selectStatisticData.getRowAqiData().getUser().getSex().toString();
        AQIId.setText(id);
        AQILocation.setText(location);
        AQILevel.setText(AQIlevel);
        AQITime.setText(time);
        NEPGMessage.setText(nepgMessage);
        NEPSMessage.setText(nepsMessage);
        NEPSDescribe.setText(describe);
    }

    public void adminOut(ActionEvent event) {
        MyUtils.navigateToView(event, "group/nepm/common/view/NEPMLoginView.fxml");
    }
    public void toPublicSuperviseDataList(ActionEvent event) {
        MyUtils.navigateToView(event, "group/nepm/publicSuperviseDataManagement/view/PublicSuperviseDataList.fxml");
    }
    public void toConfirmAqiDataList(ActionEvent event) {
        MyUtils.navigateToView(event, "group/nepm/publicSuperviseDataManagement/view/ConfirmAqiDataList.fxml");
    }
    public void toProvinceStatistic(ActionEvent event) {
        MyUtils.navigateToView(event, "group/nepm/statisticDataManagement/view/provinceStatistic.fxml");
    }
    public void toAqiDistributionStatistic(ActionEvent event) {
        MyUtils.navigateToView(event, "group/nepm/statisticDataManagement/view/aqiDistributionStatistic.fxml");
    }
    public void toAqiTendencyStatistic(ActionEvent event) {
        MyUtils.navigateToView(event, "group/nepm/statisticDataManagement/view/aqiTendencyStatistic.fxml");
    }
    public void toOtherDataStatistic(ActionEvent event) {
        MyUtils.navigateToView(event, "group/nepm/statisticDataManagement/view/otherDataStatistic.fxml");
    }

    public void back(ActionEvent actionEvent) {
        MyUtils.navigateToView(actionEvent, "group/nepm/publicSuperviseDataManagement/view/ConfirmAqiDataList.fxml");
    }
}
